<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  hide_add_course ||= false; hide_add_user ||= false
  show_course = !hide_add_course && can_do(@account, @current_user, :manage_courses)
  show_user = !hide_add_user && @account.root_account? && can_do(@account, @current_user, :manage_user_logins)
%>

<div class="rs-margin-bottom">
  <% if show_course %>
    <a href="#" role="button" class="add_course_link Button button-sidebar-wide">
      <span aria-hidden="true">{{> icons/plus}} {{#t}}New Course{{/t}}</span>
      <span class="screenreader-only">{{#t}}Add a New Course{{/t}}</span>
    </a>
  <% end %>
  <% if show_user %>
    <a href="#" role="button" class="add_user_link Button button-sidebar-wide" aria-label="{{#t}}Add a New User{{/t}}">
      <span aria-hidden="true">{{> icons/plus}} {{#t}}New User{{/t}}</span>
      <span class="screenreader-only">{{#t}}Add a New User{{/t}}</span>
    </a>
  <% end %>
  <% account_custom_links.each do |link| %>
    <a href="<%= link[:url] %>" role="button" class="Button button-sidebar-wide"><i class="<%= link[:icon_class] %>" role="presentation"></i> <%= link[:text] %></a>
  <% end %>
</div>

<% if show_course || show_user %>
<div style="display: none;">
  <div id="current_enrollment_term_id"><%= @term && @term.id %></div>
  <div id="add_user_dialog">
    <%= form_for :user, :url => account_add_user_url(@account), :html => {:id => "add_user_form"} do |f| %>
    <table class="formtable">
      <tr>
        <td><%= f.blabel :name, :full_name, :en => "Full Name" %></td>
        <td>
          <%= f.text_field :name %>
          <div class="hint-text"><%= t :full_name_description, 'This name will be used by teachers for grading.' %></div>
        </td>
      </tr>
      <tr>
        <td><%= f.blabel :short_name, :en => "Display Name" %></td>
        <td>
          <%= f.text_field :short_name %>
          <div class="hint-text">{{#t}}People will see this name in discussions, messages and comments.{{/t}}</div>
        </td>
      </tr>
      <tr>
        <td><%= f.blabel :sortable_name, :en => "Sortable Name" %></td>
        <td>
          <%= f.text_field :sortable_name %>
          <div class="hint-text">{{#t}}This name appears in sorted lists.{{/t}}</div>
        </td>
      </tr>
      <% if @root_account.login_handle_name_is_customized? || @root_account.delegated_authentication? %>
        <tr>
          <td><%= blabel :pseudonym, :path, :en => "Email" %></td>
          <td><%= text_field :pseudonym, :path %></td>
        </tr>
      <% end %>
      <tr>
        <td>
          <label for="pseudonym_unique_id">
            <%= t(:unique_id_label_1, "%{label}:", label: @root_account.login_handle_name_with_inference) %>
          </label>
        </td>
        <td><%= text_field :pseudonym, :unique_id %></td>
      </tr>
      <% if @root_account.allow_sis_import && can_do(@root_account, @current_user, :manage_sis) %>
        <tr>
          <td><%= blabel :pseudonym, :sis_user_id, :en => "SIS ID" %></td>
          <td><%= text_field :pseudonym, :sis_user_id %></td>
        </tr>
      <% end %>
      <tr>
        <td colspan="2">
          <%= check_box :pseudonym, :send_confirmation, :checked => true %>
          &nbsp;<%= label :pseudonym, :send_confirmation, :en => "Email the user about this account creation" %>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <div class="button-container">
            <button type="button" class="btn cancel_button">{{#t}}Cancel{{/t}}</button>
            <button type="submit" class="btn btn-primary submit_button">{{#t}}Add User{{/t}}</button>
          </div>
        </td>
      </tr>
    </table>
    <% end %>
  </div>
  <div id="add_course_dialog">
    <%= form_for :course, :url => courses_url, :html => {:id => "add_course_form"} do |f| %>
    <input type="hidden" name="account_id" value="<%= @account.id %>"/>
    <table class="formtable">
      <tr>
        <td><%= f.blabel :name, :en => "Course Name" %></td>
        <td><%= f.text_field :name, :style => "width: 200px;" %></td>
      </tr><tr>
        <td><%= f.blabel :course_code, :en => "Reference Code" %></td>
        <td><%= f.text_field :course_code, :style => "width: 100px;" %></td>
      </tr><tr>
        <td><%= f.blabel :account_id, :en => "Subaccount" %></td>
        <td><%= f.select :account_id, @account.sub_accounts_as_options, :selected => @term && @term.id %></td>
      </tr><tr>
        <td><%= f.label :enrollment_term_id, :en => "Enrollment Term" %></td>
        <td>{{> views/shared/enrollment_term_select}}
      </tr><tr>
        <td colspan="2">
          <div class="button-container">
            <button type="button" class="btn dialog_closer">{{#t}}Cancel{{/t}}</button>
            <button type="submit" class="btn btn-primary">{{#t}}Add Course{{/t}}</button>
          </div>
        </td>
      </tr>
    </table>
    <% end %>
  </div>
</div>


<% js_bundle :add_course_or_user %>
<% end %>
